<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>采购成本详情</title>
    <link href="/res/css/respective/priceAsk/buyer.css" rel="stylesheet">
    <script src="/res/js/common/jquery.1.9.1.min.js"></script>
</head>
<body>
<div class="warp">
[#include "/front/common/front_headAzt.html"]
    <div class="backcontent">
	[#include "/front/common/front_leftAzt.html"]
        <div class="back-main">
            <div class="mainContent">
                <div class="mainContentWhite">
                    <h1>采购成本详情</h1>
                    <label class="opDetail" style="text-align: right; float: right;">
                        <a href="/enquiry/project/detail/p/${budgets.enqEnquiry.projectId}/t/3">返回项目</a>
                    </label>
                    <hr>
                    <h2>基本信息</h2>
                    <div class="baseInfo">
                        <div>
                            <dfn>
                                询价名称：<span class="ellipsis">[#if budgets.enqEnquiry??]${budgets.enqEnquiry.enquiryName!}[/#if]</span>
                            </dfn>
                            <dfn>
                                发布公司：<span>[#if budgets.enqEnquiry??]${budgets.enqEnquiry.companyName!}[/#if]</span>
                            </dfn>
                        </div>
                        <div>
                            <dfn>
                                项目名称：<span>[#if budgets.enqEnquiry??]${budgets.enqEnquiry.enqProject.projectName!}
												[/#if]</span>
                            </dfn>

						[#if budgets.enqEnquiry.qtype==2 ]
                            <dfn>
                                支付方式：<span>
								[#if budgets.enqEnquiry??]
												${EnqPaymentEnum.getName(budgets.enqEnquiry.payment!)}
											[/#if]</span>
                            </dfn>
						[/#if]

                        </div>
                        <div>

                            <dfn>
                                客户名称：<span>[#if budgets.enqEnquiry??]${budgets.enqEnquiry.enqProject.customerName!}[/#if]</span>
                            </dfn>

                            <dfn>
                                项目所在地：<span>
							[#if budgets.enqEnquiry??]
							    ${budgets.enqEnquiry.enqProject.getAddressName("-")}
							[/#if]
								</span>
                            </dfn>

                        </div>
                        <div>
                            <dfn>
                                是否含税：<span>[#if budgets.enqEnquiry??][#if budgets.enqEnquiry.taxPrice==3]不含税[#else]含税 ${(budgets.enqEnquiry.taxInstro)!0}% [/#if] [/#if]</span>
                            </dfn>

                            <dfn>
                                是否含运费：<span>[#if budgets.enqEnquiry??]${(budgets.enqEnquiry.shipPrice==1)?string("含运费","不含运费")!}[/#if]</span>
                            </dfn>



                        </div>
                        <div>
                            <dfn>
                                质保要求：<span>[#if budgets.enqEnquiry??]${budgets.enqEnquiry.quality!}年[/#if]</span>
                            </dfn>

						[#if budgets.enqEnquiry?? && budgets.enqEnquiry.attachfile?? ]
                            <dfn>
                                项目资料：<span><a href="[#if budgets.enqEnquiry??]${budgets.enqEnquiry.attachfile!} [/#if]">附件下载</a></span>
                            </dfn>
						[/#if]
                        </div>
                    </div>
                    <hr style="margin-bottom: 15px;">
                    <div class="othNed">
                        <label style="color: #999999">其他要求：</label>
					[#if budgets.enqEnquiry??]${budgets.enqEnquiry.otherRemarks!}[/#if]
                    </div>

                    <h2>预算清单
                        <small class="itermTip">
                            <em style="vertical-align: middle;">供应商筛选：</em>
                            <div class="ppSelect" style="display: inline-block;background: url(/res/images/checkBoxRadio/blueSelect_03.jpg) right center no-repeat;height: 20px;width: auto;">
                                <select onchange="sosuo()" id="so_companyname" style="height: 100%; border: none;background: none;padding-right: 25px;width: auto;">
                                    <option value="0">所有供应商</option>
								[#list budgets.companys as company]
                                    <option value="${company.companyId}">${company.companyName}</option>
								[/#list]
                                </select>
                            </div>
                        </small>
                    </h2>
                    <table class="table noBorder">
                        <thead>
                        <tr>
                            <th>
                                <input type="checkbox" onclick="allSelect(this)"  id="allselect" />
                                全选
                            </th>
                            <th>供应商</th>
                            <th>产品类目</th>
                            <th>商品名称</th>
                            <th>品牌</th>
                            <th>型号</th>
                            <th>数量</th>
                            <th>单位</th>
                            <th>单价</th>
                            <th>技术参数</th>
                            <th>小计</th>
                        </tr>
                        </thead>
                        <tbody>
                        <!--默认显示8行-->
						[#list budgets.detailList as budget]
                        <tr class="budget budget_${budget.companyId}"  >
                            <td>
                                <input  onclick="calculate(true)" value="${budget.id}" attq="${budget.quoteId}" class="budgetclass"  attu="${budget.unitprice}"  type="checkbox"     />
                            </td>
                            <td>${budget.companyName}</td>
                            <td>${budget.categoryName}</td>
                            <td style="width: 200px;overflow: hidden;">${budget.productName}</td>
                            <td>${budget.brand!}</td>
                            <td>${budget.model!}</td>
                            <td  style="width:150px;" class="quantity quantity_${budget.quoteId}" attid="${budget.id}"   attu="${budget.unitprice}"  name="quantity"  value="${budget.quantity}"  >${budget.quantity}</td>
                            <td>${budget.unit!}</td>
                            <td>${budget.unitprice?string("currency")}</td>
                            <td>${budget.desc!}</td>
                            <td class="contentBold">${budget.totalPrice?string("currency")}</td>
                        </tr>
						[/#list]
                        </tbody>
                        <tfoot>
                        <tr class="tableBorde">
                            <td class="fenye" colspan="11"
                                style="text-align: right; background: #f8f8f8; padding: 30px 15px;">
                                清单总价：&nbsp;&nbsp;&nbsp;
                                <span id="totalPrice" class="contentBold"
                                      style="font-size: 18px; padding-right: 20px;vertical-align: middle;">${budgets.totalPrice?string("currency")}</span>
                                已选清单总价：&nbsp;&nbsp;&nbsp;
                                <span id="choosedPrice" class="contentBold"
                                      style="font-size: 18px;vertical-align: middle;">￥0.00</span>
                            </td>
                        </tr>
                        </tfoot>
                    </table>

                    <div style="margin-top: 30px;height: 45px;">
                        <button onclick="download(${budgetid!})"   class="backButt" type="button">下载完整清单</button>
					[#if budgets.enqBudget.userId == userid ]
                            <button class="buyButt" onclick="gobuy(${budgets.enqEnquiry.id})" >下单购买</button>
					[/#if]
					[#if budgets.enqBudget.userId == userid ]
                        [#--<button onclick="turnToEnq()"   class="backButt" style="float: right;" type="button" >转发采购询价</button>--]
					[/#if]
                    </div>
                </div>
            </div>
        </div>
        <!-- 底部菜单-->
	[#include "/front/common/front_footerAzt.html"]
    </div>

</div>
<div  id="datewrap" style="display: none;">
    <div style="padding: 15px;">
        <div>
            您选择对此预算，重新发起询价，请选择本次询价的截止时间，其他信息将以原预算信息为准。
        </div>

        <div>
            报价截止时间：<input id="newdeadtime" class="laydate-icon" >
        </div>

        <div >
            <button type="button" onclick="postToEnquiry(${budgetid!})"  style="padding: 5px 10px; color: white;">确定</button>
        </div>

    </div>
</div>

<script src="/res/js/buyer/buyer.js"></script>
<script src="/res/js/common/common.js"></script>
<script src="/res/js/common/jQuery.plusready.js"></script>
<script src="/res/third/layer/layer.js"></script>
<script src="/res/third/layer/layer.extends.js"></script>
<script src="/res/third/laydate/laydate.js"></script>
<script src="/res/js/common/jquery.ellipsis.js"></script>
<script type="text/javascript" >
$(function(){
	$(".ellipsis").ellipsis({maxWidth:290,maxLine:1});
});
    /*下载*/
    function download(budgetid){
        location.href="/enquiry/budget/detail/download/"+budgetid;
    }

    /*数量插件*/
    $(".quantity").plusready({callback:function (obj, num) {
        var price = parseFloat($(obj).attr("attu"))*parseFloat(num);
        $(obj).parent().find(".contentBold").text($.my.currency(price,true));
        //更新清单总价
        calculate(false);
        //更新已选总价
        calculate(true);
    }});



    function allSelect(obj){
        $(".budgetclass").each(function (i) {
            $(this)[0].checked=$(obj).is(":checked");
        });
        calculate(true);
    }


    //计算选择的价格
    function calculate(ischecked){

        var isallall=true;
        $(".budgetclass").each(function () {
            var ischecked = $(this).is(":checked");
            if(!ischecked){
                $("#allselect")[0].checked=false;
                isallall = false;
                return false;
            }
        });
        if(isallall){
            $("#allselect")[0].checked=true;
        }


        var v = $("#so_companyname").val();
        var price = 0.0;
        var searchobj;
        if(v==0){
            searchobj = $(".budget");
        }else{
            searchobj = $(".budget_"+v);
        }
        searchobj.each(function () {
            var obj = $(this).find(".budgetclass").eq(0);
            var ochecked = obj[0].checked;
            if((!ochecked) && ischecked){
               return true;
            }
            var uprice = obj.attr("attu");
            var quantity = $(this).find(".quantity").attr("value");
            price = price + parseFloat(quantity)*parseFloat(uprice);
        });

        if(ischecked){
            $("#choosedPrice").text($.my.currency(price,true));
        }else{
            $("#totalPrice").text($.my.currency(price,true));
        }

    }



    function sosuo() {
        var v = $("#so_companyname").val();
        if(v==0){
            $(".budget").show();
        }else{
            $(".budget").hide();
            $(".budget_"+v).show();
        }
        calculate(true);
    }

    /**
     * 预算转采购弹
     */
    laydate({
        elem: '#newdeadtime',
        event: 'focus',
        min:laydate.now()
    });

    function postToEnquiry(budgetid) {
        var  deadtime = $("#newdeadtime").val();

        if(deadtime==null || deadtime==""){
            layer.msgShort("请选择时间");
        }else {
            layer.post({
                url:"/enquiry/budget/to/purchase",
                data:{budgetid:budgetid,deadtime:deadtime},
                success:function (data) {
                    layer.closeAll();
                    layer.alert("转发采购成功",function () {
                        location.href="/enquiry/project/detail/p/"+data.obj+"/t/3";
                    });
                }

            },"正在提交");
        }
    }
    function turnToEnq() {
        layer.open({
            title:"重新发起询价",
            type:1,
            btn:false,
            content: $('#datewrap')
        });
    }

    //下单
    function gobuy(enquiryid) {
        var ids =[];
        var attqs =[];

        var v = $("#so_companyname").val();
        var price = 0.0;
        var searchobj;
        if(v==0){
            searchobj = $(".budget");
        }else{
            searchobj = $(".budget_"+v);
        }
        searchobj.each(function () {
            var obj = $(this).find(".budgetclass").eq(0);
            if(obj.is(":checked")){
                ids.push(obj.val());
                var quoteid =obj.attr("attq");
                if($.inArray(quoteid,attqs)== -1 ){
                    attqs.push(quoteid);
                }
            }
        });

        if(ids.length==0){
            layer.msgShort("至少选择一个商品购买!");
            return false;
        }

        var d = [];
        attqs.forEach(function (v) {
            var o ={};
            o.quoteId = v;
            o.items=[];
            $(".quantity_"+v).each(function () {
                var itemid = $(this).attr("attid");
                var value = $(this).attr("value");
                if($.inArray(itemid,ids)!=-1){
                    var oc ={};
                    oc.itemId =itemid;
                    oc.quantity =value;
                    o.items.push(oc);
                }
            });
            d.push(o);
        });
        $.my.postForm("/order/submit/quote",{enquiryId:enquiryid,item:JSON.stringify(d)});
        //location.href="/order/submit?enquiryId="+enquiryid+"&item="+JSON.stringify(d);
    }
</script>
</body>
</html>
